package com.weetop.cfw.home_page.activity

import android.os.Bundle
import com.blankj.utilcode.util.ToastUtils
import com.weetop.cfw.R
import com.weetop.cfw.base.ui.activity.CommonBaseActivity
import com.weetop.cfw.bean.ErrorBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils
import kotlinx.android.synthetic.main.activity_tou_su.*

class TouSuActivity : CommonBaseActivity() {
    override fun getLayoutId() = R.layout.activity_tou_su
    var infoId = ""

    override fun initView(savedInstanceState: Bundle?) {
        infoId=intent.getStringExtra("infoId")
        ck01.setOnCheckedChangeListener { buttonView, isChecked ->
            if (isChecked) {
                ck02.isChecked = false
                ck03.isChecked = false
                ck04.isChecked = false
                ck05.isChecked = false
            }
        }
        ck02.setOnCheckedChangeListener { buttonView, isChecked ->
            if (isChecked) {
                ck01.isChecked = false
                ck03.isChecked = false
                ck04.isChecked = false
                ck05.isChecked = false
            }
        }
        ck03.setOnCheckedChangeListener { buttonView, isChecked ->
            if (isChecked) {
                ck01.isChecked = false
                ck02.isChecked = false
                ck04.isChecked = false
                ck05.isChecked = false
            }
        }
        ck04.setOnCheckedChangeListener { buttonView, isChecked ->
            if (isChecked) {
                ck01.isChecked = false
                ck02.isChecked = false
                ck03.isChecked = false
                ck05.isChecked = false
            }
        }
        ck05.setOnCheckedChangeListener { buttonView, isChecked ->
            if (isChecked) {
                ck01.isChecked = false
                ck02.isChecked = false
                ck03.isChecked = false
                ck04.isChecked = false
            }
        }
    }

    override fun initData(savedInstanceState: Bundle?) {
        submit.setOnClickListener {
            if (ck01.isChecked || ck02.isChecked || ck03.isChecked || ck04.isChecked || ck05.isChecked) {
                if (ck01.isChecked) {
                    submit("联系方式不正确（空号）", "联系方式不正确（空号）")
                }
                if (ck02.isChecked) {
                    submit("联系方式无人接听", "联系方式无人接听")
                }
                if (ck03.isChecked) {
                    submit("此房已出租出售", "此房已出租出售")
                }
                if (ck04.isChecked) {
                    submit("房源信息不准确", "房源信息不准确")
                }
                if (ck05.isChecked) {
                    submit("其它", "其它")
                }
            }
        }
    }

    fun submit(reason: String, title: String) {
        RxJavaUtils.useInAppCompatActivityOnDestory(
            RetrofitUtils.getApi().infoSuggest(
                infoId,
                title,
                reason
            ), this, object :
                RxJavaCallBack<ErrorBean>() {
                override fun onSuccess(t: ErrorBean?) {
                    ToastUtils.showShort("投诉已提交")
                    finish()
                }

                override fun onErrorResponse(throwable: Throwable?) {
                    super.onErrorResponse(throwable)
                }

                override fun onRequestError(t: ErrorBean?) {
                    super.onRequestError(t)
                }

            })
    }
}
